<?php
include_once (SERVER_ROOT_PATH . '/Inc/Lib/Openapi/Openapi_qq.php');
class ml_model_openapiQq extends Lib_openapi_abstract {
    /*
     * 检测返回code
     */
    public function check_auth($code) {
        OpenSDK_Tencent_Weibo::init ( OPENAPI_QQ_APP_KEY, OPENAPI_QQ_APP_TOKEN );
        $rt = OpenSDK_Tencent_Weibo::getAccessToken ( $code );
        return $rt;
    }
    
    /*
     * 获取授权用链接
     */
    public function get_auth_url() {
        OpenSDK_Tencent_Weibo::init ( OPENAPI_QQ_APP_KEY, OPENAPI_QQ_APP_TOKEN );
        $callback = OPENAPI_CALLBACK_URL . '?type=tencent';
        $request_token = OpenSDK_Tencent_Weibo::getRequestToken ( $callback );
        return $url = OpenSDK_Tencent_Weibo::getAuthorizeURL ( $request_token );
    }
    
    /*
     * 获取用户基本信息
     */
    public function get_user_info() {
        OpenSDK_Tencent_Weibo::init ( OPENAPI_QQ_APP_KEY, OPENAPI_QQ_APP_TOKEN );
        $return = OpenSDK_Tencent_Weibo::call ( 'user/info' );
        if ($return ['errcode'] == 0) {
            $userinfo = array ();
            $userinfo ['nickname'] = $return ['data'] ['nick'];
            $userinfo ['gender'] = $return ['data'] ['sex'] == 1 ? 'm' : ($return ['data'] ['sex'] == 2 ? 'f' : 'n');
            $userinfo ['birthday'] = $return ['data'] ['birth_year'] . '-' . $return ['data'] ['birth_month'] . '-' . $return ['data'] ['birth_day'];
            /* $userinfo ['province_id'] = '';
            $userinfo ['city_id'] = $return ['data'] ['city_code']; */
            $userinfo ['head_url'] = $return ['data'] ['head'].'/';
            return $userinfo;
        } else
            return false;
    }
    
    /*
     * (non-PHPdoc) @see Lib_openapi_abstract::sent_message()
     */
    public function sent_message() {
    
    }

}
